package org.top10.parser;

import java.io.Reader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.top10.dealor.TagDealor;
import org.top10.entity.HotArticle;
import org.top10.entity.Tag;


public class TianYaParser {
	private final static String SIGN="热贴榜";
	private TagDealor dealor;
	private String key;
	private int type;
	public List<HotArticle> parse(String key) {
		
			//dealor=new TagDealor(input);
			List<HotArticle> list=new ArrayList<HotArticle>();
			try {
				String text=dealor.getTagTextByName("ul", SIGN);
				LinkedList<Tag> tags=dealor.findTags(text,"a", 0);
				if(tags==null||tags.size()<=1)return null;
				int rank=1;
				for(int t=0;t<tags.size();t++){
					HotArticle article=new HotArticle();
					article.setRank(rank++);
					Tag a=tags.get(t++);
					article.setName(dealor.getTextBetweenTags(a, tags.get(t),text));
					article.setReadUrl(a.getProps().get("href"));
					list.add(article);
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			
			return list;
	}
}
